package com.yy.job.console.converter;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;

import com.yy.job.common.dao.po.YYJobStepDO;
import com.yy.job.common.dao.po.YYJobStepLogDO;
import com.yy.job.common.utils.date.YYDateUtils;
import com.yy.job.console.dto.JobStepLogView;

public class JobStepLogViewConverter {

	public static JobStepLogView convert(YYJobStepLogDO jobStepLogDO, YYJobStepDO jobStepDO) {
		JobStepLogView consoleDTO = new JobStepLogView();
		BeanUtils.copyProperties(jobStepLogDO, consoleDTO);
		consoleDTO.setExecStartTimeFormat(YYDateUtils.formatDateTimeDefault(jobStepLogDO.getExecStartTime()));
		consoleDTO.setExecEndTimeFormat(YYDateUtils.formatDateTimeDefault(jobStepLogDO.getExecEndTime()));
		consoleDTO.setJobStepCode(jobStepDO.getStepCode());
		consoleDTO.setJobStepName(jobStepDO.getStepName());
		if("Y".equals(jobStepLogDO.getJobStepResultFlag())) {
			consoleDTO.setJobStepResultFlagName("成功");
		} else if("N".equals(jobStepLogDO.getJobStepResultFlag())) {
			consoleDTO.setJobStepResultFlagName("失败");
		}

		return consoleDTO;
	}

	public static List<JobStepLogView> listConvert(List<YYJobStepLogDO> jobDOs,
			Map<Long, YYJobStepDO> jobStepMap) {
		if (jobDOs == null) {
			return null;
		}
		return jobDOs.stream().map(e -> convert(e, jobStepMap.get(e.getJobStepId()))).collect(Collectors.toList());
	}

}
